Skip to content

Conversation

who
Copy link
Contributor

@who who commented Jul 13, 2015

I've improved the configuration file support in the PHP codegen so that composer vendor name, composer project name, composer version, and namespace are all configurable.

Here's the new output of the config-help for php:

java -jar ./modules/swagger-codegen-cli/target/swagger-codegen-cli.jar config-help -l php

CONFIG OPTIONS
    modelPackage
        package for generated models

    apiPackage
        package for generated api classes

    invokerPackage
        The main namespace to use for all classes.

    packagePath
        The main package name for classes.

    srcBasePath
        The directory under packagePath to serve as source root.

    composerVendorName
        The vendor name used in the composer package name. The template uses {{composerVendorName}}/{{composerProjectName}} for the composer package name.

    composerProjectName
        The project name used in the composer package name. The template uses {{composerVendorName}}/{{composerProjectName}} for the composer package name.

    artifactVersion
        The composer package version used to generate the composer.json file.

@who who changed the title Support for customizing Composer fields [PHP] Support for customizing Composer fields Jul 13, 2015
@who
Copy link
Contributor Author

who commented Jul 13, 2015

Here is an example of what this PR allows, given the petstore 2.0 spec:

Given this config json...

{
    "invokerPackage": "Yay\\Pets",
    "modelPackage": "Yay\\Pets\\MyModelPackage",
    "apiPackage": "Yay\\Pets\\MyApiPackage",
    "packagePath": "GeneratedPetstore",
    "composerProjectName": "petstore-client",
    "composerVendorName": "yaypets",
    "artifactVersion": "1.2.3"
}

... this is the swagger-codegen output ...

java -jar ./modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate -l php -i http://petstore.swagger.io/v2/swagger.json -o output -c config.json
reading config from config.json
reading from http://petstore.swagger.io/v2/swagger.json
writing file /tmp/tmp.cxkWt5lE73/swagger-codegen/output/GeneratedPetstore/lib/MyModelPackage/Order.php
writing file /tmp/tmp.cxkWt5lE73/swagger-codegen/output/GeneratedPetstore/lib/MyModelPackage/Category.php
writing file /tmp/tmp.cxkWt5lE73/swagger-codegen/output/GeneratedPetstore/lib/MyModelPackage/User.php
writing file /tmp/tmp.cxkWt5lE73/swagger-codegen/output/GeneratedPetstore/lib/MyModelPackage/Tag.php
writing file /tmp/tmp.cxkWt5lE73/swagger-codegen/output/GeneratedPetstore/lib/MyModelPackage/Pet.php
writing file /tmp/tmp.cxkWt5lE73/swagger-codegen/output/GeneratedPetstore/lib/MyModelPackage/ApiResponse.php
writing file /tmp/tmp.cxkWt5lE73/swagger-codegen/output/GeneratedPetstore/lib/MyApiPackage/UserApi.php
writing file /tmp/tmp.cxkWt5lE73/swagger-codegen/output/GeneratedPetstore/lib/MyApiPackage/PetApi.php
writing file /tmp/tmp.cxkWt5lE73/swagger-codegen/output/GeneratedPetstore/lib/MyApiPackage/StoreApi.php
writing file /tmp/tmp.cxkWt5lE73/swagger-codegen/output/GeneratedPetstore/lib/Configuration.php
writing file /tmp/tmp.cxkWt5lE73/swagger-codegen/output/GeneratedPetstore/lib/ApiClient.php
writing file /tmp/tmp.cxkWt5lE73/swagger-codegen/output/GeneratedPetstore/lib/ApiException.php
writing file /tmp/tmp.cxkWt5lE73/swagger-codegen/output/GeneratedPetstore/lib/ObjectSerializer.php
writing file /tmp/tmp.cxkWt5lE73/swagger-codegen/output/GeneratedPetstore/composer.json
writing file /tmp/tmp.cxkWt5lE73/swagger-codegen/output/GeneratedPetstore/autoload.php

... and this is the file tree of generated output ...

GeneratedPetstore/
├── autoload.php
├── composer.json
└── lib
    ├── ApiClient.php
    ├── ApiException.php
    ├── Configuration.php
    ├── MyApiPackage
    │   ├── PetApi.php
    │   ├── StoreApi.php
    │   └── UserApi.php
    ├── MyModelPackage
    │   ├── ApiResponse.php
    │   ├── Category.php
    │   ├── Order.php
    │   ├── Pet.php
    │   ├── Tag.php
    │   └── User.php
    └── ObjectSerializer.php

... and this is the composer.json:

{
    "name": "yaypets/petstore-client",
    "version": "1.2.3",
    "description": "",
    "keywords": [
        "swagger",
        "php",
        "sdk",
        "api"
    ],
    "homepage": "http://swagger.io",
    "license": "Apache v2",
    "authors": [
        {
            "name": "Swagger and contributors",
            "homepage": "https://github.com/swagger-api/swagger-codegen"
        }
    ],
    "require": {
        "php": ">=5.3.3",
        "ext-curl": "*",
        "ext-json": "*",
        "ext-mbstring": "*"
    },
    "require-dev": {
        "phpunit/phpunit": "~4.0",
        "satooshi/php-coveralls": "~0.6.1",
        "squizlabs/php_codesniffer": "~2.0"
    },
    "autoload": {
        "psr-4": { "Yay\\Pets\\" : "lib/" }
    }
}

@who
Copy link
Contributor Author

who commented Jul 13, 2015

@wing328 let me know if you need me to elaborate on any of this.

@wing328
Copy link
Contributor

wing328 commented Jul 14, 2015

@who thanks for the PR! I'll review and let you know if I've any questions.

@who who changed the title [PHP] Support for customizing Composer fields [PHP] Support for customizing Composer fields and namespaces Jul 14, 2015
@who who changed the title [PHP] Support for customizing Composer fields and namespaces [PHP] Support for customizing namespace and Composer fields Jul 14, 2015
@wing328
Copy link
Contributor

wing328 commented Jul 15, 2015

Unit testing looks good:

SwaggerClient-php|develop_2.0 ⇒ ./vendor/bin/phpunit tests




PHPUnit 4.7.7 by Sebastian Bergmann and contributors.

............

Time: 8.86 seconds, Memory: 16.75Mb

OK (12 tests, 2576 assertions)

Tested with the config json provided and the result also looks good.

wing328 added a commit that referenced this pull request Jul 15, 2015
[PHP] Support for customizing namespace and Composer fields
@wing328 wing328 merged commit 1f097ee into swagger-api:develop_2.0 Jul 15, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants